package com.cgbl.service.ui

import android.os.Bundle
import com.alibaba.android.arouter.facade.annotation.Route
import com.cgbl.service.BR
import com.cgbl.service.R
import com.cgbl.service.assist.ProjectAssist
import com.cgbl.service.databinding.AppActivityMyProjectDetailBinding
import com.cgbl.service.pop.CloseProjectPop
import com.cgbl.service.pop.CommonConfirmPop
import com.cgbl.service.vm.MyProjectDetailViewModel
import com.lxj.xpopup.XPopup
import com.robot.base.base.activity.GLBaseActivity
import com.robot.base.configs.AppConstants
import com.robot.base.model.ProjectBean
import com.robot.base.util.LiveDataEventManager

@Route(path = AppConstants.Router.Project.A_MY_PROJECT_DETAIL)
class MyProjectDetailActivity :
    GLBaseActivity<AppActivityMyProjectDetailBinding, MyProjectDetailViewModel>() {

    var id = ""

    override fun initContentView(savedInstanceState: Bundle?): Int =
        R.layout.app_activity_my_project_detail

    override fun initVariableId(): Int = BR.viewModel

    override fun initComponents() {
        addSingleTitleBar("项目名称")
        viewModel.fetchProjectProfile(id)
    }

    override fun initViewObservable() {
        viewModel.uc.showCloseDialog.observe(this) {
            val closeProjectPop = CloseProjectPop(this@MyProjectDetailActivity)
            XPopup.Builder(this@MyProjectDetailActivity).asCustom(closeProjectPop).show()
        }
        viewModel.uc.showEndProjectEvent.observe(this) {
            val commonConfirmPop = CommonConfirmPop(this@MyProjectDetailActivity)
            XPopup.Builder(this@MyProjectDetailActivity).asCustom(commonConfirmPop).show()
            commonConfirmPop.setTitle("结束项目?").setLeftText("取消").setRightText("确定")
                .setDesc("结束项目，人员酬劳将发送到账户中").setRightClickListener {

                }
        }
        LiveDataEventManager.observerRefreshProjectProfileEvent(this) {
            viewModel.fetchProjectProfile(ProjectAssist.getCurrentProjectId())
        }
    }

    override fun initParam() {
        id = intent.getStringExtra(AppConstants.BundleKey.ID) ?: ""
    }
}